﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>BlueTone Calls</title>
    <meta name="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
    <style type="text/css">
        .left {float: left;}
        #content {width: auto; position: relative;}
    #phone {position: absolute; z-index: 3; top: 38px; left: 12px; width: 113px; height: 126px;}
    #sites {border: 1px solid #666666; background-color: #CCCCCC; width: 52.083%; position: relative; margin: 0 23.95%}
    #infobar {width: 181px; height: 50px; background: url('callfrom.png') repeat-x; position: absolute; z-index: 2; color: #FFF; padding-left: 119px;}
    hr {width: 50%; margin: 5px auto;}
    .site {margin-bottom: 10px;}
    
    a.dp-choose-date {
	float: left;
	width: 16px;
	height: 16px;
	padding: 0;
	margin: 5px 3px 0;
	display: block;
	text-indent: -2000px;
	overflow: hidden;
	background: url(http://www.bluetonemedia.com/images/scripts/calendar.png) no-repeat; 
}
a.dp-choose-date.dp-disabled {
	background-position: 0 -20px;
	cursor: default;
}
/* makes the input field shorter once the date picker code
 * has run (to allow space for the calendar icon
 */
input.dp-applied {
	width: 140px;
	float: left;
}
#results {display: none; width: 52.083%; position: relative; margin: 0 23.95%}
#callfrom {width: 52.083%; position: relative; margin: 0 23.95%}
#calllist {margin: 0; padding: 0;}
#calllist li {cursor: pointer; list-style: none; border-bottom: 1px solid #000; margin: 10px 12%;}
#calllist li:last-child {border-bottom: none;}

@media screen and (max-width: 720px) {
	#callfrom, #results, #sites {margin: 0; width: 100%;}
	#sites {}	
}

@media screen and (min-width: 720px) {
	#callfrom, #results, #sites {}
	#content, input {font-size: 28px;}	
	textarea {font-size: 28px;}
}
    </style>

    
<script type="text/javascript" src="http://www.bluetonemedia.com/images/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="http://www.bluetonemedia.com/images/scripts/date.js"></script>
<!--[if lt IE 7]><script type="text/javascript" src="scripts/jquery.bgiframe.min.js"></script><![endif]-->
<!-- jquery.datePicker.js -->
<script type="text/javascript" src="http://www.bluetonemedia.com/images/scripts/jquery.datePicker.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="http://www.bluetonemedia.com/images/scripts/datePicker.css">
<script type="text/javascript">
        Date.format = 'mm/dd/yyyy';
var contactnames;
var contactname;
var employees = [
    ["500", "Jimmy Honsinger"],
    ["501", "Alan Everson"],
    ["502", "Megan Tarble"],
    ["503", "Brian Carroll"],
    ["504", "Brad Graham"],
    ["505", "Scott Clements"],
    ["506", "Domonique Dixon"],
    ["507", "Peter Demaria"],
	["508", "Joshua Krautwurst"],
    ["509", "Dev Room"],
    ["510", "Design Room"],
    ["512", "Kevin McNamee"],
    ["530", "Conf Room"],
    ["531", "Break Room"]
];

$(function () {
    var old_number = "";
    var ext = "";
	var requestInfo = false;
	
    //$.ajax({
//            url: 'calls.aspx',
//            success: function (msg) {
//                var tempnum = msg;
//
//                if (old_number != tempnum) {
//                    $('#calllist').html('');
//                    getresults();
//                    old_number = tempnum;
//                }
//				
//				//setInterval(function () {
//        		//	startItUp();
//    			//}, 5000);
//            }
//        });

    getresults();
	 
    function startItUp() {
        $.ajax({
            url: 'calls.aspx',
            success: function (msg) {
                var tempnum = msg;

                if (old_number != tempnum) {
                    $('#calllist').html('');
                    getresults();
                    old_number = tempnum;
                }
            }
        });
    }

	function recentResults(firsttext, firstnum) {
		requestInfo = false;
	    var cnames = firsttext;
	    var datastring = "number=" + firstnum;
		
	    $.ajax({
	        url: 'callinfo.aspx',
	        data: datastring,
	        success: function (msg2) {
	            //alert(msg2);
	            if (msg2 == "None") {
					//alert(firsttext + " " + firstnum);
	                var contactname = cnames.split("\"");
	                var contactnumber = firstnum.replace("+",  "");  //contactname[2].split("+");
					
	                //contactnumber = contactnumber[1].replace(">", "");

	                $('#results').html(contactname[1] + '<br/><a href="addexisting.aspx?num=' + contactnumber + '">Add to Existing Company</a>&nbsp;&nbsp;&nbsp;<a href="NewCompany.aspx?num=' + contactnumber + '">Create New Company</a><br/>');
	                $('#results').fadeIn();
				} else if (msg2 == "Is in the company datatable, but not in the contacts table") {
					 var contactname = cnames.split("\"");
					$('#results').html(contactname[1] + '<br/>' + msg2);
	            } else {
	                var info = msg2.split("` ");

	                $('#infobar span').text(info[0]);

	                $('#results').html('<div class="site">' + msg2 + '</div>');
	                $('.date').datePicker().val(new Date().asString()).trigger('change');
	                $('#results').fadeIn();
	            }
				
				requestInfo = true;
	        }
	    });
	}
	
    function getresults() {
		var requestFinished = false;
		
		
        $.ajax({
            url: 'calls.aspx',
            success: function (msg) {
                var nu = msg.split("~");

				$('#calllist').html('');
				
                for (var w = 0; w < nu.length; w++) {
                    var msgs = nu[w].split("`");

                    if (msgs[0].length == 10) {
                        msgs[0] = "+1" + msgs[0];
                    } else if (msgs[0].length == 11) {
                        msgs[0] = "+" + msgs[0];
                    }

                    if (msgs[0] != old_number && msgs[0].length > 3 && (msgs[0] != "+19107952280")) {
                        contactnames = msgs[1];
						
                        for (var empl = 0; empl < employees.length; empl++) {
                            if (msgs[2] == employees[empl][0]) {
                                ext = employees[empl][1];
                                break;
                            } else {
                                ext = msgs[2];
                            }
                        }

						var msgss = msgs[1].split("<");
						var check;
						
						if (msgs[3] == 1) {
							check = "CRM"; //"<img src='/images/bluetonecalls2/images/check.png' />";
						} else {
							check = "";
						}
						
						
                        $('#calllist').append('<li>' + check + '&nbsp;&nbsp;' + msgs[4] + '&nbsp;&nbsp;<span class="name">' + msgss[0] + '</span><span class="number"><a href="tel:' + msgs[0] + '">' + msgs[0] + '</a></span> to ' + ext + '</li>');
                    }
                }

				recentResults($('.name:first').text(), $('.number:first').text());
				
                $('#calllist li').click(function () {
					recentResults($('.name', this).text(), $('.number', this).text());
                });
				
				requestFinished = true;	
				
				setTimeout(function () {
        			if(requestFinished) {
						getresults();
					}
    			}, 60000);			
            }
        });
    }
});
</script>
</head>
<body>
<div id="content">

<div id="callfrom">Phone Call From:</div>
<div id="results"></div>
<div id="sites"><ul id="calllist"></ul></div>

</div>
</body>
</html>
